<template>
  <div class="upgrade-config" v-if="upgradeList.updatePathIndex" keep-live>
    <div class="upgrage-index">
      <div class="upgrade-route">
        <h2 class="upgrade-route-title">升级路径首页</h2>
        <!--升级路径-->
        <div class="intro">
          <span>介绍</span>
          <el-input v-if="upgradeRouteFlag" type="textarea"
                    v-model="upgradeList.updatePathIndex.introduction"></el-input>
          <p v-else>
            {{upgradeList.updatePathIndex.introduction}}
          </p>
        </div>
        <div class="upgrade-route">
          <span>升级路径</span>
          <el-table
            :data="upgradeList.updatePathIndex.updatePath"
            v-loading.fullscreen.lock="loading"
            element-loading-text="拼命加载中~"
            style="width: 100%">
            <el-table-column
              type="index"
              label="排序"
              width="80">
            </el-table-column>
            <el-table-column
              prop="name"
              label="名称"
              width="100">
              <template scope="scope">
                <span v-if="!upgradeRouteFlag">{{scope.row.name}}</span>
                <span v-else>
                <el-input v-model="scope.row.name" :placeholder="scope.row.name"></el-input>
              </span>
              </template>
            </el-table-column>
            <el-table-column
              prop="illustrate"
              label="说明">
              <template scope="scope">
                <span v-if="!upgradeRouteFlag">{{scope.row.illustrate}}</span>
                <span v-else>
                <el-input v-model="scope.row.illustrate" :placeholder="scope.row.illustrate"></el-input>
              </span>
              </template>
            </el-table-column>
            <el-table-column label="图片">
              <template scope="scope">
                <span v-if="!upgradeRouteFlag"><img :src="scope.row.imgUrl"/></span>
                <span v-else>
                <el-input type="textarea" v-model="scope.row.imgUrl" :id="`img-${scope.$index}`" name="imgUrl"
                          :placeholder="scope.row.imgUrl"></el-input>
              </span>
              </template>
            </el-table-column>
            <el-table-column
              style="margin:0 auto"
              prop="url"
              label="链接">
              <template scope="scope">
                <span v-if="!upgradeRouteFlag">{{scope.row.url}}</span>
                <span v-else>
                <el-input v-model="scope.row.url" :placeholder="scope.row.url"></el-input>
              </span>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="edit-btn">
          <el-button v-if="!upgradeRouteFlag" type="primary" size="small" @click="formEdit('upgradeRouteFlag')">编  辑
          </el-button>
          <el-button v-else type="success" size="small" @click="formSave('upgradeRouteFlag')">保  存</el-button>
        </div>
      </div>
    </div>
    <!--申请页-->
    <div class="apply-page">
      <h2 class="apply-page-title">
        申请页
      </h2>
      <el-form label-width="100px" :model="upgradeList.apllicationPage">
        <el-form-item label="预览图">
          <img class="header-image" v-if="!applyPageFlag" :src="upgradeList.apllicationPage.headerImg" alt="">
          <el-input v-else type="textarea" v-model="upgradeList.apllicationPage.headerImg"></el-input>
        </el-form-item>
        <el-form-item label="权益及优惠">
          <el-input :disabled="!applyPageFlag" type="textarea"
                    v-model="upgradeList.apllicationPage.promotion"></el-input>
        </el-form-item>
        <el-form-item label="积分政策">
          <template>
            <el-form-item label="积分积累规则">
              <el-input :disabled="!applyPageFlag" v-model="upgradeList.apllicationPage.points.rule"></el-input>
            </el-form-item>
            <el-form-item label="积分有效期">
              <el-input :disabled="!applyPageFlag" v-model="upgradeList.apllicationPage.points.validity"></el-input>
            </el-form-item>
            <el-form-item label="积分转金币政策">
              <el-input :disabled="!applyPageFlag" v-model="upgradeList.apllicationPage.points.goldenCoin"></el-input>
            </el-form-item>
          </template>
        </el-form-item>
        <el-form-item label="费用信息">
          <template>
            <el-form-item label="年费">
              <el-input :disabled="!applyPageFlag" v-model="upgradeList.apllicationPage.spendInfo.annualFee"></el-input>
            </el-form-item>
            <el-form-item label="免年费政策">
              <el-input :disabled="!applyPageFlag" v-model="upgradeList.apllicationPage.spendInfo.exempt"></el-input>
            </el-form-item>
            <el-form-item label="卡片工本费">
              <el-input :disabled="!applyPageFlag"
                        v-model="upgradeList.apllicationPage.spendInfo.costForCard"></el-input>
            </el-form-item>
            <el-form-item label="货币兑换率">
              <el-input :disabled="!applyPageFlag"
                        v-model="upgradeList.apllicationPage.spendInfo.conversionPercent"></el-input>
            </el-form-item>
            <el-form-item label="免息期">
              <el-input :disabled="!applyPageFlag" v-model="upgradeList.apllicationPage.spendInfo.freeData"></el-input>
            </el-form-item>
            <el-form-item label="预借现金比例">
              <el-input :disabled="!applyPageFlag"
                        v-model="upgradeList.apllicationPage.spendInfo.cashAdvancePercent"></el-input>
            </el-form-item>
            <el-form-item label="预借现金手续费">
              <el-input :disabled="!applyPageFlag"
                        v-model="upgradeList.apllicationPage.spendInfo.cashAdvanceCast"></el-input>
            </el-form-item>
          </template>
        </el-form-item>
        <el-form-item label="链接">
          <el-input :disabled="!applyPageFlag" v-model="upgradeList.apllicationPage.spendInfo.url"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button v-if="!applyPageFlag" type="primary" size="small" @click="formEdit('applyPageFlag')">编  辑
          </el-button>
          <el-button v-else type="success" size="small" @click="formSave('applyPageFlag')">保  存</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!--绑定页-->
    <div class="bundle-page">
      <h2 class="bundle-page-title">
        绑定页
      </h2>
      <el-input width="200px" class="bind-page-btn" :disabled="!bindUrlFlag"
                v-model="upgradeList.bundlePage.url"></el-input>
      <el-button v-if="!bindUrlFlag" type="primary" size="small" @click="formEdit('bindUrlFlag')">编  辑</el-button>
      <el-button v-else type="success" size="small" @click="formSave('bindUrlFlag')">保  存</el-button>
    </div>


  </div>
</template>

<script type="text/ecmascript-6">
  import axios from 'axios'
  export default{
    data () {
      return {
        upgradeList: {},
        upgradeRouteFlag: false,
        applyPageFlag: false,
        bindUrlFlag: false,
        loading: false
      }
    },
    mounted () {
      this.getUpgradeData()
    },
    methods: {
      // 获取数据
      getUpgradeData () {
        this.loading = true
        axios.get('/node/api/profile-update').then((res) => {
          this.upgradeList = res.data.profileUpdateModel
          this.loading = false
        })
      },
      // 更新数据
      updateUpgradeData () {
        let param = {profileUpdateModel: this.upgradeList}
        axios.post('/node/api/profile-update', param).then((res) => {
          this.$notify({
            title: '成功',
            message: '保存成功！',
            type: 'success'
          })
        })
      },
      // 编辑
      formEdit (flag) {
        this[flag] = true
      },
      // 保存
      formSave (flag) {
        this[flag] = false
        this.updateUpgradeData()
      }
    }
  }
</script>

<style lang="less" rel="stylesheet/less">
  .upgrade-config {
    .upgrage-index, .apply-page, .bundle-page {
      border: 1px solid #eee;
      padding: 20px;
      margin-bottom: 10px;
    }
    h2[class*='-title'] {
      background: #eee;
      line-height: 30px;
      font-size: 20px;
      font-weight: 900;
      margin-bottom: 10px;
    }
    .upgrage-index {
      .upgrade-route {
        img.defaultBg {
          width: 120px;
          height: 30px;
          background: url() no-repeat gray 50%;
        }
        .intro, .upgrade-route {
          margin-top: 20px;
          & > span {
            width: 80px;
            font-size: 14px;
          }
          & > p {
            font-size: 14px;
          }
          display: flex;
        }
        .edit-btn {
          margin-top: 10px;
          text-align: center;
        }
      }
    }
    .apply-page{
      .header-image{
        width: 200px;
      }
    }
  }

</style>
